package com.zmx.product.web.rest;

import com.zmx.product.api.ProductApi;
import com.zmx.product.dto.ProductDto;
import com.zmx.product.entity.Product;
import com.zmx.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 商品信息对内接口
 * @ClassName: ProductRest
 * @Author zhaomxr
 * @Date 2021-11-04 11:19
 */
@Slf4j
@RestController
public class ProductRest implements ProductApi {

    @Autowired
    private ProductService productService;

    @Override
    public ProductDto findById(Long productId) {
        return productService.findDtoById(productId);
    }

    @Override
    public List<ProductDto> findByIdIn(Long[] productIds) {

        List<ProductDto> productDtos = new ArrayList<ProductDto>(productIds.length);

        for (Long productId : productIds) {
            ProductDto productDto = productService.findDtoById(productId);
            productDtos.add(productDto);
        }
        if (productDtos == null || productDtos.size() == 0) {
            productDtos = productService.findDtoByIdIn(productIds);
        }

        return productDtos;
    }

    @Override
    public List<ProductDto> getProductListByProductSn(Long productId) {
        return productService.getProductListByProductSn(productId);
    }
}
